home *** CD-ROM | disk | FTP | other *** search
- ; Context Sensitive Help in Any Editor -- by Rajat
- ; http://www.autohotkey.com
- ; This script makes Ctrl+2 (or another hotkey of your choice) show the help file
- ; page for the selected AutoHotkey command or keyword. If nothing is selected,
- ; the command name will be extracted from the beginning of the current line.
-
- ; The hotkey below uses the clipboard to provide compatibility with the maximum
- ; number of editors (since ControlGet doesn't work with most advanced editors).
- ; It restores the original clipboard contents afterward, but as plain text,
- ; which seems better than nothing.
-
- $^2::
- ; The following values are in effect only for the duration of this hotkey thread.
- ; Therefore, there is no need to change them back to their original values
- ; because that is done automatically when the thread ends:
- SetWinDelay 10
- SetKeyDelay 0
- AutoTrim, On
-
- if A_OSType = WIN32_WINDOWS ; Windows 9x
- Sleep, 500 ; Give time for the user to release the key.
-
- C_ClipboardPrev = %clipboard%
- clipboard =
- ; Use the highlighted word if there is one (since sometimes the user might
- ; intentionally highlight something that isn't a command):
- Send, ^c
- ClipWait, 0.1
- if ErrorLevel <> 0
- {
- ; Get the entire line because editors treat cursor navigation keys differently:
- Send, {home}+{end}^c
- ClipWait, 0.2
- if ErrorLevel <> 0 ; Rare, so no error is reported.
- {
- clipboard = %C_ClipboardPrev%
- return
- }
- }
- C_Cmd = %clipboard% ; This will trim leading and trailing tabs & spaces.
- clipboard = %C_ClipboardPrev% ; Restore the original clipboard for the user.
- Loop, parse, C_Cmd, %A_Space%`, ; The first space or comma is the end of the command.
- {
- C_Cmd = %A_LoopField%
- break ; i.e. we only need one interation.
- }
- IfWinNotExist, AutoHotkey Help
- {
- ; Use non-abbreviated root key to support older versions of AHK:
- RegRead, ahk_dir, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotkey, InstallDir
- if ErrorLevel <> 0
- {
- ; Older versions of AHK might not have the above registry entry,
- ; so use a best guess location instead:
- ahk_dir = %A_ProgramFiles%\AutoHotkey
- }
- ahk_help_file = %ahk_dir%\AutoHotkey.chm
- IfNotExist, %ahk_help_file%
- {
- MsgBox, Could not find the help file: %ahk_help_file%.
- return
- }
- Run, %ahk_help_file%
- WinWait, AutoHotkey Help
- }
- ; The above has set the "last found" window which we use below:
- WinActivate
- WinWaitActive
- StringReplace, C_Cmd, C_Cmd, #, {#}
- send, !n{home}+{end}%C_Cmd%{enter}
- return
-